﻿using System;
using System.Runtime.Serialization;

namespace ModelLayer
{
    [DataContract]
    public class Edge : IComparable<Edge>
    {
        public Edge(Node firstNode, Node secondNode)
        {
            FirstNode = firstNode;
            SecondNode = secondNode;

            Visited = false;
        }

        public Edge(Node firstNode, Node secondNode, double distance)
            : this(firstNode, secondNode)
        {
            Distance = distance;
        }

        public Edge(Node firstNode, Node secondNode, double distance, TimeSpan time)
            : this(firstNode, secondNode, distance)
        {
            Time = time;
        }

        public Edge(long firstNode, long secondNode, double distance, TimeSpan time)
        {
            FirstNode = new Node(new Station { Id = firstNode });
            SecondNode = new Node(new Station { Id = secondNode });
            Distance = distance;
            Time = time;
        }

        public Edge()
        {
        }

        [DataMember]
        public Node FirstNode { get; set; }

        [DataMember]
        public Node SecondNode { get; set; }

        [DataMember]
        public double Distance { get; set; }

        [DataMember]
        public TimeSpan Time { get; set; }

        public void Reset()
        {
            Visited = false;
        }

        public int CompareTo(Edge otherEdge)
        {
            return Distance.CompareTo(otherEdge.Distance);
        }

        [DataMember]
        public bool Visited { get; set; }
    }
}